package com.example.demo02.dto;

import cn.hutool.core.lang.Opt;
import com.example.demo02.constants.ParameterConstant;
import com.example.demo02.entity.Shop;
import com.example.demo02.utils.ParamUtils;
import lombok.Data;


import java.util.List;
import java.util.Map;

@Data
public class ShopInfo extends Shop {
    private String optunitName;
    private String parkpotName;


    public static ShopInfo from(Shop shop, Map<Integer,String> shopParkNameMap,Map<String,String> optunitNameMap){
        ShopInfo shopInfo = new ShopInfo();
        shopInfo.setShopid(shop.getShopid());
        shopInfo.setShopName(shop.getShopName());
        String parkpotName = shopParkNameMap.get(shop.getShopid());
        shopInfo.setParkpotName(parkpotName);
        String optName = Opt.ofNullable(optunitNameMap).map(map->map.get(shop.getOptunitid().toString())).get();
        shopInfo.setOptunitName(optName);
        //封装商家状态
        shopInfo.setShopState(ParamUtils.getParamMemo(ParameterConstant.SHOP_STATE,shop.getShopState()));

        return shopInfo;
    }
}
